本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以是多个。
输入格式:
输入给出一行字符。
输出格式:
在一行中输出单词个数。
输入样例:
1 | Let's go to room 209. |
输出样例:
1 | 5 |
鸣谢用户 张麦麦 补充数据!
思路
getline输入字符串,扫描字符串
遇到字母时,若这个字母的前一个字符不是空格,则是一个新单词
代码
1 |
|
本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以是多个。
输入给出一行字符。
在一行中输出单词个数。
1 | Let's go to room 209. |
1 | 5 |
鸣谢用户 张麦麦 补充数据!
getline输入字符串,扫描字符串
遇到字母时,若这个字母的前一个字符不是空格,则是一个新单词
1 |
|